cmake_minimum_required(VERSION 3.0)

project(liblog4x)

file(GLOB_RECURSE PROJECT_HEADERS *.h)
file(GLOB_RECURSE PROJECT_CPPS    *.cpp)

set(SOURCES ${PROJECT_HEADERS} ${PROJECT_CPPS})

if(WIN32)
    file(GLOB_RECURSE OSRCS os/unix/*)
    list(APPEND SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/log4x.rc)
else()
    file(GLOB_RECURSE OSRCS os/win/*)
endif()
list(REMOVE_ITEM SOURCES ${OSRCS})

source_group_by_dir(SOURCES)
set(HEADERS log4x.h log4x-c.h echo/log4xecho.h)

include_directories(
    ${PROJECT_ROOT_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}
	os
    os/win
    os/unix
    echo
    )

if(WIN32)
    add_definitions(-DLOG4X_EXPORTS)
    link_libraries(shlwapi psapi)
else()
    add_definitions(-Wno-deprecated-declarations)
    link_libraries(-pthread)
endif()

if(BUILD_SHARED_LIBS)
    add_library(log4x SHARED ${SOURCES} ${HEADERS})
    if (MINGW)
        set(CMAKE_SHARED_LIBRARY_PREFIX "")
    endif()

    install(TARGETS log4x DESTINATION lib)
    if(WIN32)
        install(TARGETS log4x RUNTIME DESTINATION bin)
    endif()
endif()

if(BUILD_STATIC_LIBS)
    add_library(log4x_static STATIC ${SOURCES} ${HEADERS})
    # set_target_properties(log4x_static PROPERTIES OUTPUT_NAME "log4x")
    install(TARGETS log4x_static DESTINATION lib)
endif()

install(FILES ${HEADERS} DESTINATION include/log4x)
